-- =============================================
-- Author:		<Le Dang Minh>
-- Create date: <01/26/2010>
-- Description:	<Create Update TimeSheet Record Store Procedure>
-- =============================================
--EXEC TimeSheet_usp_Update_Record_TimeSheet '2','2','2','2','2','01/23/2010','4','TEST'
USE TimeSheet
GO
IF EXISTS(SELECT * FROM sys.objects WHERE type = 'P' AND name = 'TimeSheet_usp_Update_Record_TimeSheet')
     DROP PROCEDURE TimeSheet_usp_Update_Record_TimeSheet
GO
CREATE PROCEDURE TimeSheet_usp_Update_Record_TimeSheet 
	-- Add the parameters for the stored procedure here
	@TimeSheetId BIGINT,
	@ProjectId BIGINT,
	@ProductId INT,
	@ProcessId INT,
	@WorkId INT,
	@Date DATETIME,
	@Time FLOAT,
	@Description NTEXT
AS
BEGIN
	IF EXISTS(SELECT tt.TimeSheetId FROM ts_timesheet tt WHERE tt.TimeSheetId = @TimeSheetId AND tt.StatusId != 2)
	BEGIN
	  UPDATE ts_timesheet
	  SET
		Date = @Date,
		[Time] = @Time,
		[Description] = @Description,
		ProductId = @ProductId,
		WorkId = @WorkId,
		ProcessId = @ProcessId,
		ProjectId = @ProjectId
	  WHERE
	  TimeSheetId = @TimeSheetId AND StatusId != 2
	END
	ELSE
		RAISERROR('This record is not exist or is approved!!',11,1)
END	
GO
